********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global ed4topfa "dT1dtop66e14fa dT2dtop66e14fa dT3dtop66e14fa dT4dtop66e14fa dT5dtop66e14fa dT7dtop66e14fa dT8dtop66e14fa dT9dtop66e14fa dT10dtop66e14fa dT11dtop66e14fa dT12dtop66e14fa"
global ed4midfa "dT1dmid6633e14fa dT2dmid6633e14fa dT3dmid6633e14fa dT4dmid6633e14fa dT5dmid6633e14fa dT7dmid6633e14fa dT8dmid6633e14fa dT9dmid6633e14fa dT10dmid6633e14fa dT11dmid6633e14fa dT12dmid6633e14fa"
global controls "lncrefin dT*exlnassets dT*excashas"
global regcommands ", pool(2) compact absorb(bankid borrowerid#time) vce(cluster bankid)"


**# Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans2019, case(lower)
run RO_creditregister tm(2019m2) tm(2020m2) 0
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2019, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(dtop66e14 dtop33e14 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m2, keepus(dtop66e14f dtop33e14f)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2019m3)&time<=tm(2020m2)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

gen dtop66e14fa=dtop66e14f*dtop66e14
gen dtop33e14fa=dtop33e14f*dtop33e14
gen dmid6633e14fa=0
replace dmid6633e14fa=1 if dtop33e14fa==1&(dtop66e14==0|dtop66e14f==0)
drop dtop33e14f dtop33e14

run RO_tdummies 2019 12
run RO_tdintera 12 "dtop66e14fa dmid6633e14fa exlnassets excashas"

**# Bookmark (output - column 1)
est clear
cd $outputdirectory
reghdfe $y $ed4topfa $ed4midfa $controls $regcommands
est save TABIIF_C12
cd ..

********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global ed3topdj "dT1dtop85e13dj dT2dtop85e13dj dT3dtop85e13dj dT4dtop85e13dj dT5dtop85e13dj dT7dtop85e13dj dT8dtop85e13dj dT9dtop85e13dj dT10dtop85e13dj dT11dtop85e13dj dT12dtop85e13dj"
global controls "lncrefin dT*exlnassets dT*excashas"
global regcommands ", pool(2) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**# Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(dtop85e13 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m6, keepus(dtop85e13j)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)
gen dtop85e13dj=dtop85e13*dtop85e13j

run RO_tdummies 2015 12
run RO_tdintera 12 "dtop85e13dj exlnassets excashas"

**# Bookmark (output - column 2)
est clear
cd $outputdirectory
reghdfe $y $ed3topdj $controls $regcommands
est save TABIIF_C12, append
cd ..
